Let's look at how you actually run an application on Cloud Run. After your web application is packaged into a container image, you can run it anywhere. On Google Cloud, you can run containers on a Compute
Engine in a virtual machine, or on a Kubernetes
cluster or in Cloud Run. On your local machine, you can use Docker or Podman. Both are container runtimes. Let's look at what
happens when you deploy your container
image to Cloud Run. When you deploy a container
image for the first time, Cloud Run creates a service. In a later module, we'll further define what a service is. But for now you should know that the service holds
a container image. There is only one container
image per service. Each service has a
unique HTTPS endpoints on a sub-domain of
the run.app domain. Cloud Run forwards incoming
requests to a container. To handle those requests, Cloud Run starts the container. Cloud Run dynamically adds
and removes containers as needed to handle
all incoming requests. This is called auto-scaling, and we'll return to that
topic after the lab. You can also route
incoming traffic to your Cloud Run service through
the global load balancer. We will look at that in more
detail in a later module. Let's pause here and
direct your attention to the word service because this is a key concept
in Cloud Run. Services are created to enable the deployment of a
containerized image. Every service has
a unique name and then associated HTTPS endpoint. A service keeps track
of the configuration of your container image and
any changes you make to it. You'll interact primarily with a service resource to
perform your tasks, such as deploying a
new container image, rolling back to a previously
deployed version, and changing configuration
settings like environment variables
and scaling boundaries. Let's take a step
back and look at how your container image
gets to Cloud Run. When you deploy an image, you don't send it
directly to Cloud Run. You'll need to use
Artifact Registry as the intermediate
storage location for it. Because Cloud Run can only pull container images from
Artifact Registry. Even if you usually host your container images
somewhere else, remember that with Cloud Run, you'll still need to push them to Artifact Registry first. Artifact Registry is a
fully managed service in Google Cloud and was
formerly known as Google Container
Registry or GCR. Artifact Registry is a
universal package manager and is used to privately
host container images, Node.js packages
or Java packages. To host your container images, you create a Docker repository that Cloud Run can pull
container images from. Let's look at how that works. When you're ready to deploy your container
image to Cloud Run, you begin by pushing, that's the term
used for uploading, the image to a Docker repository
on Artifact Registry. Your container image will
have a unique name in the repository which you can use when you
deploy to Cloud Run. After your container
image has been pushed into the
Docker repository, you can deploy it to a
service on Cloud Run. This means you
hand the container reference over to Cloud Run, which then pulls the image
from Artifact Registry. This is what a developer does to deploy a container image. You open the web console or GCloud terminal interface
and enter a command to create or update an
existing service resource with the reference to
the container image. Finally, Cloud Run pulls the container image from
the Docker repository. To ensure that
containers on Cloud Run start reliably and quickly, Cloud Run copies and stores
the container image locally. The internal container
storage is fast, which ensures that
your image size is not an obstruction, increasing your
container startup time. Large images load as
quickly as small ones. Because Cloud Run
copies the image, you won't get into trouble
if you accidentally delete a deployed container image
from Artifact Registry. The copy ensures that
your Cloud Run service will continue to work. Before we start
the hands-on lab, let's just take a look at the options users
have available to interact with Google Cloud and manage their Cloud
Run resources. The web console and the GCloud terminal
command line interface. The web interface is a
great way to get started. Most Google Cloud products, including Cloud Run
feature polished, getting started
wizards that guide you through creating
your first resources. The GCloud command
line interface offers a good user experience for those who like the command line. You can write
scripts and you get helpful suggestions if
you mistype a command. Knowing how to use the
command line will help if you decide to automate some
or all of your processes. Another way to manage Cloud Run resources is with Terraform, a third party tool
that lets you use a declarative approach
to provisioning and maintaining your
Cloud infrastructure. Terraform works this way, you describe all of the
Cloud resources needed and the links between them using
a configuration language. Terraform builds
your entire project from this specification. This is also known as
infrastructure as code. It helps you build consistent and
reproducible environments, making collaboration with a team on a shared project easier. There are other
third-party options for managing your Cloud
run applications, but Terraform is highlighted here because the integration
of Terraform with Google Cloud is very solid and is maintained by dedicated
team at Google Cloud.